package com.net.io.nio.three.component.z.demo.client;

import java.util.Scanner;

import static com.net.io.nio.three.component.z.demo.Const.DEFAULT_PORT;
import static com.net.io.nio.three.component.z.demo.Const.DEFAULT_SERVER_IP;

/**
 * @author zhangtengfei
 * @date 2022/1/29 14:12
 */
public class NioClient {
    private static NioClientHandle nioClientHandle;

    public static void start() {
        nioClientHandle = new NioClientHandle(DEFAULT_SERVER_IP, DEFAULT_PORT);
        new Thread(nioClientHandle, "Server").start();
    }

    /**
     * 向服务器发送消息
     */
    public static boolean sendMsg(String msg) throws Exception {
        nioClientHandle.sendMsg(msg);
        return true;
    }

    public static void main(String[] args) throws Exception {
        start();
        Scanner scanner = new Scanner(System.in);
        while (NioClient.sendMsg(scanner.next())) {
        }
    }
}
